from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-06 14:12:32.760487
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 06, Aug, 2021
Time: 14:12:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5472
Nobs: 375.000 HQIC: -46.1155
Log likelihood: 4017.89 FPE: 6.45424e-21
AIC: -46.4897 Det(Omega_mle): 5.09307e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.490838 0.097040 5.058 0.000
L1.Burgenland 0.106267 0.050182 2.118 0.034
L1.Kärnten -0.116658 0.024043 -4.852 0.000
L1.Niederösterreich 0.162645 0.106550 1.526 0.127
L1.Oberösterreich 0.085846 0.105296 0.815 0.415
L1.Salzburg 0.292922 0.051281 5.712 0.000
L1.Steiermark 0.012439 0.067854 0.183 0.855
L1.Tirol 0.138090 0.053886 2.563 0.010
L1.Vorarlberg -0.109448 0.048287 -2.267 0.023
L1.Wien -0.057714 0.094087 -0.613 0.540
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.024886 0.234259 -0.106 0.915
L1.Burgenland -0.030243 0.121143 -0.250 0.803
L1.Kärnten 0.036093 0.058041 0.622 0.534
L1.Niederösterreich -0.222459 0.257219 -0.865 0.387
L1.Oberösterreich 0.554102 0.254190 2.180 0.029
L1.Salzburg 0.307585 0.123795 2.485 0.013
L1.Steiermark 0.110306 0.163802 0.673 0.501
L1.Tirol 0.307555 0.130085 2.364 0.018
L1.Vorarlberg -0.020147 0.116568 -0.173 0.863
L1.Wien -0.004864 0.227131 -0.021 0.983
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.262143 0.050219 5.220 0.000
L1.Burgenland 0.096577 0.025970 3.719 0.000
L1.Kärnten -0.005208 0.012442 -0.419 0.676
L1.Niederösterreich 0.226195 0.055140 4.102 0.000
L1.Oberösterreich 0.147183 0.054491 2.701 0.007
L1.Salzburg 0.039256 0.026538 1.479 0.139
L1.Steiermark 0.018055 0.035115 0.514 0.607
L1.Tirol 0.075176 0.027887 2.696 0.007
L1.Vorarlberg 0.056034 0.024989 2.242 0.025
L1.Wien 0.084908 0.048691 1.744 0.081
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199935 0.049097 4.072 0.000
L1.Burgenland 0.044071 0.025389 1.736 0.083
L1.Kärnten -0.005153 0.012164 -0.424 0.672
L1.Niederösterreich 0.125817 0.053909 2.334 0.020
L1.Oberösterreich 0.300760 0.053274 5.646 0.000
L1.Salzburg 0.099175 0.025945 3.822 0.000
L1.Steiermark 0.142245 0.034330 4.143 0.000
L1.Tirol 0.076663 0.027264 2.812 0.005
L1.Vorarlberg 0.057227 0.024431 2.342 0.019
L1.Wien -0.042402 0.047603 -0.891 0.373
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205655 0.098462 2.089 0.037
L1.Burgenland -0.059375 0.050918 -1.166 0.244
L1.Kärnten -0.038088 0.024395 -1.561 0.118
L1.Niederösterreich 0.068149 0.108112 0.630 0.528
L1.Oberösterreich 0.190528 0.106839 1.783 0.075
L1.Salzburg 0.268141 0.052033 5.153 0.000
L1.Steiermark 0.084072 0.068848 1.221 0.222
L1.Tirol 0.128499 0.054676 2.350 0.019
L1.Vorarlberg 0.121546 0.048995 2.481 0.013
L1.Wien 0.034918 0.095466 0.366 0.715
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.033644 0.077429 0.435 0.664
L1.Burgenland 0.022409 0.040041 0.560 0.576
L1.Kärnten 0.052508 0.019184 2.737 0.006
L1.Niederösterreich 0.197395 0.085017 2.322 0.020
L1.Oberösterreich 0.344305 0.084016 4.098 0.000
L1.Salzburg 0.049363 0.040917 1.206 0.228
L1.Steiermark -0.002912 0.054141 -0.054 0.957
L1.Tirol 0.114385 0.042996 2.660 0.008
L1.Vorarlberg 0.065444 0.038529 1.699 0.089
L1.Wien 0.124932 0.075072 1.664 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164671 0.093391 1.763 0.078
L1.Burgenland 0.036028 0.048295 0.746 0.456
L1.Kärnten -0.053965 0.023139 -2.332 0.020
L1.Niederösterreich -0.108564 0.102544 -1.059 0.290
L1.Oberösterreich 0.184896 0.101336 1.825 0.068
L1.Salzburg 0.027430 0.049353 0.556 0.578
L1.Steiermark 0.300304 0.065302 4.599 0.000
L1.Tirol 0.487278 0.051860 9.396 0.000
L1.Vorarlberg 0.075263 0.046471 1.620 0.105
L1.Wien -0.110402 0.090549 -1.219 0.223
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156690 0.102535 1.528 0.126
L1.Burgenland -0.009219 0.053024 -0.174 0.862
L1.Kärnten 0.064295 0.025404 2.531 0.011
L1.Niederösterreich 0.203446 0.112584 1.807 0.071
L1.Oberösterreich -0.130143 0.111258 -1.170 0.242
L1.Salzburg 0.249048 0.054185 4.596 0.000
L1.Steiermark 0.156473 0.071696 2.182 0.029
L1.Tirol 0.047213 0.056938 0.829 0.407
L1.Vorarlberg 0.124833 0.051022 2.447 0.014
L1.Wien 0.140578 0.099415 1.414 0.157
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.523768 0.055295 9.472 0.000
L1.Burgenland -0.023099 0.028595 -0.808 0.419
L1.Kärnten -0.009555 0.013700 -0.697 0.486
L1.Niederösterreich 0.189544 0.060714 3.122 0.002
L1.Oberösterreich 0.248882 0.059999 4.148 0.000
L1.Salzburg 0.021672 0.029221 0.742 0.458
L1.Steiermark -0.023305 0.038664 -0.603 0.547
L1.Tirol 0.074093 0.030705 2.413 0.016
L1.Vorarlberg 0.060360 0.027515 2.194 0.028
L1.Wien -0.060673 0.053612 -1.132 0.258
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021784 0.069975 0.128996 0.111420 0.028986 0.062600 -0.003029 0.172058
Kärnten 0.021784 1.000000 -0.059417 0.132085 0.044577 0.052216 0.446427 -0.092842 0.102334
Niederösterreich 0.069975 -0.059417 1.000000 0.285064 0.089398 0.277848 0.016887 0.140766 0.254382
Oberösterreich 0.128996 0.132085 0.285064 1.000000 0.173660 0.295710 0.165364 0.118217 0.127248
Salzburg 0.111420 0.044577 0.089398 0.173660 1.000000 0.124574 0.044652 0.103602 0.048377
Steiermark 0.028986 0.052216 0.277848 0.295710 0.124574 1.000000 0.123921 0.086435 -0.026978
Tirol 0.062600 0.446427 0.016887 0.165364 0.044652 0.123921 1.000000 0.040514 0.129510
Vorarlberg -0.003029 -0.092842 0.140766 0.118217 0.103602 0.086435 0.040514 1.000000 -0.050117
Wien 0.172058 0.102334 0.254382 0.127248 0.048377 -0.026978 0.129510 -0.050117 1.000000